﻿using H.Sync.Http;
using System;
using System.IO;

namespace H.Sync
{
    /// <summary>
    /// 用于与远程接口通信,确定需要更新的文件,并进行更新的同步核心
    /// </summary>
    public class SyncCore
    {
        /// <summary>
        /// 远程提供服务的主机
        /// </summary>
        private readonly string Host;

        /// <summary>
        /// 远程提供服务的主机的端口
        /// </summary>
        private readonly int Port;

        /// <summary>
        /// 初始化一个新的云更新同步核心
        /// </summary>
        /// <param name="host"></param>
        /// <param name="port"></param>
        public SyncCore(string host, int port = 80)
        {
            Host = host;
            Port = port;
        }

        /// <summary>
        /// 将本地文件夹同步到远程服务器上
        /// </summary>
        /// <param name="path">需要被上传的文件夹</param>
        /// <param name="replace">是否替换重复的文件</param>
        /// <param name="delete">是否删除服务上有的,本地没有的文件</param>
        public static void UploadDir(string basePath, string path, bool replace, bool delete)
        {
            //string[] files = Directory.GetFiles(path);
            HttpClient client = new HttpClient();

            HttpResult result = client.UploadFile("http://127.0.0.1:3333/index.php/upload?path=hello.txt&token=8888", "file", "build.bat", File.ReadAllBytes(@"D:\Dev\H\HScriptCore\Output\build.bat"));
            Console.WriteLine(result.StatusCode);
            Console.WriteLine(result.ContentStr);
            //foreach (string file in files)
            //{
            //    if (Directory.Exists(file))
            //    {

            //    } else
            //    {

            //    }
            //}
        }


    }
}
